package com.fqgj.sentry.biz.mc;

import com.fqgj.sentry.biz.mc.domain.ModifyBaseInfo;
import com.fqgj.sentry.biz.mc.vo.user.UserVo;
import com.fqgj.sentry.manage.entity.McUserEntity;
import com.fqgj.sentry.manage.service.BaseInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * Created by ykpbean kangping.ying@yuntu-inc.com
 *
 * @description
 * @create 2017-07-15 下午10:36
 */

@Component
public class BaseInfoBusiness {
    @Autowired
    private BaseInfoService baseInfoService;

    public UserVo queryBaseInfo(Long userId) {
        McUserEntity userEntity = baseInfoService.selectBaseInfo(userId);
        UserVo userVo = new UserVo();
        String userIdCode = String.valueOf(userEntity.getId());
        userVo.setUserId(userIdCode)
                .setName(userEntity.getName())
                .setAccount(userEntity.getAccount())
                .setLevel(userEntity.getLevel())
                .setMobile(userEntity.getMobile())
                .setGmtModified(userEntity.getGmtModified());
        return userVo;
    }

    public Boolean modifyBaseInfo(Long userId, ModifyBaseInfo modifyBaseInfo) {
        McUserEntity userEntity = baseInfoService.selectBaseInfo(userId);
        userEntity.setGmtModified(new Date());
        userEntity.setName(modifyBaseInfo.getName())
                .setMobile(modifyBaseInfo.getMobile());
        baseInfoService.updateBaseInfo(userEntity);
        return true;
    }

    public Boolean modifyPassWord(Long userId, String newPassWord, String oldPassWord) {

        return baseInfoService.modifyPassWord(userId, newPassWord, oldPassWord);
    }
}
